package vip.xiaonuo.smzq.modular.xxgs.controller;

import javax.annotation.Resource;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.auth.core.pojo.SaBaseLoginUser;
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
import vip.xiaonuo.smzq.modular.xxgs.entity.Lsks;
import vip.xiaonuo.smzq.modular.xxgs.entity.param.LsksPageQuery;
import vip.xiaonuo.smzq.modular.xxgs.entity.vo.KsxxgslxVo;
import vip.xiaonuo.smzq.modular.xxgs.service.ILsksService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;


/**
 * 信息公示--绿色矿山
 *
 * @author sqq
 * @since 2024-07-19
 */
@Api(tags = "信息公示--绿色矿山")
@RestController
@RequestMapping("/xxgs/lsks")
@Validated
public class LsksController {

    @Resource
    private ILsksService iLsksService;

    /**
     * 添加信息公示--绿色矿山
     */
    @ApiOperation("添加信息公示--绿色矿山")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Lsks lsks) {
        //获取用户信息
        SaBaseLoginUser saBaseLoginUser = StpLoginUserUtil.getLoginUser();
        lsks.setCzrid(saBaseLoginUser.getId());
        lsks.setCzrxm(saBaseLoginUser.getName());
        lsks.setCzsj(DateUtil.format(new Date(), "YYYY-MM-dd"));
        lsks.setDelflag(0);
        iLsksService.save(lsks);
        return CommonResult.ok();
    }

    /**
     * 删除信息公示--绿色矿山
     */
    @ApiOperation("删除信息公示--绿色矿山")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iLsksService.updateDelete(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑信息公示--绿色矿山
     */
    @ApiOperation("编辑信息公示--绿色矿山")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Lsks lsks) {
        lsks.setDelflag(0);
        iLsksService.updateById(lsks);
        return CommonResult.ok();
    }

    /**
     * 信息公示--绿色矿山分页查询
     */
    @ApiOperation("信息公示--绿色矿山分页查询")
    @PostMapping("/list")
    public CommonResult<Page<Lsks>> page(@RequestBody @Valid LsksPageQuery lsksPageQuery) {
        return CommonResult.data(iLsksService.page(lsksPageQuery));
    }

    /**
     * 矿业权人右上角信息公示类型
     */
    @ApiOperation("矿业权人右上角信息公示类型")
    @GetMapping("/getKsxxgslxVo")
    public CommonResult<KsxxgslxVo> getKsxxgslxVo() {
        return CommonResult.data(iLsksService.getKsxxgslxVo());
    }
}
